import { useEffect, useState } from "react";
import { fetchLogin } from "./store/modules/user";
import { useDispatch } from "react-redux";
const Button = () => {

  const [user, setUser] = useState({
    userAccount: "yupi",
    userPassword: "12345678"
  })

  const dispatch = useDispatch()

  // const login = async () => {
  //   const res = await UserApi.login(user)
  //   console.log(res);
  // }
  // 触发异步aciton fetchLogin
  const login = (user) => {
    dispatch(fetchLogin(user))
  }

  return (
    <div>

      <button onClick={() => login(user)} > Click me!</button>
    </div>
  )
}

function App() {
  const [count, setCount] = useState(0)

  const [student, setStudent] = useState(
    {
      name: "jack",
      age: 20
    })
  const decrease = () => {
    setCount(count - 1)
  }

  const increase = () => {
    setCount(count + 1)
  }

  const handleClick = (name, e) => {
    console.log(name, e);
  }
  const changeStudent = () => {
    setStudent({
      ...student,
      name: "nihao"
    })
  }
  return (
    <div className="App">
      <button onClick={(e) => handleClick('jack', e)}>获取参数</button>
      <button onClick={decrease}>-</button>
      {count}
      <button onClick={increase}>+</button>
      <Button />
      <button onClick={() => changeStudent()}>{student.name}</button>

    </div>
  );
}

export default App;
